package au.com.shiftyjelly.pocketcasts.utils.featureflag

import au.com.shiftyjelly.pocketcasts.helper.BuildConfig

private val isDebugOrPrototypeBuild = BuildConfig.DEBUG || BuildConfig.IS_PROTOTYPE

enum class Feature(
    val key: String,
    val title: String,
    val defaultValue: Boolean,
    val tier: FeatureTier,
    val hasFirebaseRemoteFlag: Boolean,
    val hasDevToggle: Boolean,
) {
    SYNC_EOY_DATA_ON_STARTUP(
        key = "sync_eoy_data_on_startup",
        title = "Whether the End of Year data should be synced on startup",
        defaultValue = false,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = false,
    ),
    END_OF_YEAR_2025(
        key = "end_of_year_2025",
        title = "End of Year 2025",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = false,
    ),
    INTRO_PLUS_OFFER_ENABLED(
        key = "intro_plus_offer_enabled",
        title = "Intro Offer Plus",
        defaultValue = false,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    SLUMBER_STUDIOS_YEARLY_PROMO(
        key = "slumber_studios_yearly_promo_code",
        title = "Slumber Studios Yearly Promo",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Plus(null),
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    EXPLAT_EXPERIMENT(
        key = "explat_experiment",
        title = "ExPlat Experiment",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    ENGAGE_SDK(
        key = "engage_sdk",
        title = "Integrate Pocket Casts with Engage SDK",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = false,
    ),
    PODCASTS_SORT_CHANGES(
        key = "podcasts_sort_changes",
        title = "Podcasts Sort Changes",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    GUEST_LISTS_NETWORK_HIGHLIGHTS_REDESIGN(
        key = "guest_lists_network_highlights_redesign",
        title = "Guest Lists and Network Highlights Redesign",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    LIBRO_FM(
        key = "libro_fm",
        title = "Libro FM in Upsell",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Plus(),
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    RECOMMENDATIONS(
        key = "recommendations",
        title = "Recommendations",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    NOTIFICATIONS_REVAMP(
        key = "notifications_revamp",
        title = "Notifications Revamp",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    BANNER_ADS_PLAYER(
        key = "banner_ad_player",
        title = "Banner Ads Player",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    BANNER_ADS_PODCASTS(
        key = "banner_ad_podcasts",
        title = "Banner Ads Podcasts",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    SMART_CATEGORIES(
        key = "smart_categories",
        title = "Smart Categories",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    NEW_ONBOARDING_UPGRADE(
        key = "new_onboarding_upgrade",
        title = "New Onboarding Upgrade",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    NEW_ONBOARDING_ACCOUNT_CREATION(
        key = "new_onboarding_account_creation",
        title = "New Onboarding Account Creation",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    NEW_ONBOARDING_RECOMMENDATIONS(
        key = "new_onboarding_recommendations_changes",
        title = "New Onboarding Recommendation Changes",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    NEW_ONBOARDING_UPGRADE_TRIAL_TIMELINE(
        key = "new_onboarding_upgrade_trial_timeline",
        title = "New Onboarding Upgrade Trial Timeline",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    SHARE_TRANSCRIPTS(
        key = "share_transcripts",
        title = "Share transcripts",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    IMPROVED_SEARCH_SUGGESTIONS(
        key = "search_predictive",
        title = "Predictive search suggestions",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    IMPROVED_SEARCH_RESULTS(
        key = "search_improvements",
        title = "Improved search results",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),
    IMPROVE_APP_RATINGS(
        key = "improve_app_ratings",
        title = "Banner prompting for app rating",
        defaultValue = isDebugOrPrototypeBuild,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = true,
        hasDevToggle = true,
    ),

    // This is set of features used only for testing purposes.
    TEST_FREE_FEATURE(
        key = "test_free_feature",
        title = "Free feature used for testing",
        defaultValue = true,
        tier = FeatureTier.Free,
        hasFirebaseRemoteFlag = false,
        hasDevToggle = false,
    ),
    TEST_PLUS_FEATURE(
        key = "test_plus_feature",
        title = "Plus feature used for testing",
        defaultValue = true,
        tier = FeatureTier.Plus(),
        hasFirebaseRemoteFlag = false,
        hasDevToggle = false,
    ),
    TEST_PLUS_RESTRICTED_FEATURE(
        key = "test_plus_restricted_feature",
        title = "Plus feature with Patron exclusive access used for testing",
        defaultValue = true,
        tier = FeatureTier.Plus(ReleaseVersion(1, 0)),
        hasFirebaseRemoteFlag = false,
        hasDevToggle = false,
    ),
    TEST_PATRON_FEATURE(
        key = "test_patron_feature",
        title = "Patron feature used for testing",
        defaultValue = true,
        tier = FeatureTier.Patron,
        hasFirebaseRemoteFlag = false,
        hasDevToggle = false,
    ),
}

sealed class FeatureTier {
    data object Free : FeatureTier()

    class Plus(
        val patronExclusiveAccessRelease: ReleaseVersion? = null,
    ) : FeatureTier()

    data object Patron : FeatureTier()
}
